package com.the_ring.behavior.memento;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: t22306139
 * @date: 2023/12/1  15:04
 */
public class Caretaker {

    private List<Memento> mementoList = new ArrayList<>();

    public void setMemento(Memento memento) {
        mementoList.add(memento);
    }

    public Memento getMemento() {
        Memento memento = null;
        if (mementoList.size() > 0) {
            memento = mementoList.get(mementoList.size()- 1);
            // 恢复后一处这个状态
            mementoList.remove(mementoList.size() - 1);
        }
        return memento;
    }
}
